package com.bootcamp.javase.file;

import java.io.File;

/**
 * @program: FIleCode
 * @description:
 * @author: Keyu Li
 * @create: 2021-09-08 14:39
 **/

public class FileFilterTest {
    public static void main(String[] args) {
        File dir = new File("../object/filter");
        System.out.println(dir.exists());
        FileUtils.printDirResur(dir, 0);
        System.out.println();
        File files1[] = dir.listFiles((file)->
                file.isDirectory()&&file.getName().contains("a"));
        File files2[] = dir.listFiles((file)->
                file.isFile()&&file.getName().endsWith(".txt"));
        File files3[] = dir.listFiles((file)->
                file.isFile()&&file.getName().startsWith("a"));
        System.out.println("仅留下文件夹名包括a的文件夹");
        for (File file : files1) {
            System.out.print(file.getName()+"   ");
        }
        System.out.println();
        System.out.println("仅留下.txt结尾的文本文件");
        for (File file : files2) {
            System.out.print(file.getName()+"   ");
        }
        System.out.println();
        System.out.println("仅留下以a开头的文件");
        for (File file : files3) {
            System.out.print(file.getName()+"   ");
        }
        System.out.println();
    }
}
